using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace MoEngine
{
    public class WindowScene : Window
    {
        public WindowScene(WindowBase parent)
            : base(parent)
        {
            m_Viewport = MasterWnd.Device.Viewport;
        }

        protected Viewport m_Viewport;
        public Viewport Viewport
        {
            get { return m_Viewport; }
        }

        protected Scene m_Scene;
        public Scene Scene
        {
            get { return m_Scene; }
            set { m_Scene = value; }
        }

        protected override void OnLayoutValidated()
        {
            base.OnLayoutValidated();

            m_Viewport.X = (int)GlobalPosition.X;
            m_Viewport.Y = (int)GlobalPosition.Y;
            m_Viewport.Width = (int)Size.X;
            m_Viewport.Height = (int)Size.Y;

            if (m_Scene != null && m_Scene.Camera != null)
            {

                bool needResetRatio = (AspectRatio != m_Scene.Camera.AspectRatio);
                if (needResetRatio)
                    m_Scene.Camera.AspectRatio = AspectRatio;
            }
        }

        public override void Draw(GameTime time)
        {
            if (m_Scene != null && m_Scene.Camera != null)
            {
                Viewport defaultViewport = MasterWnd.Device.Viewport;

                MasterWnd.Device.Viewport = m_Viewport;


                m_Scene.Render();

                MasterWnd.Device.Viewport = defaultViewport;
            }

            base.Draw(time);
        }
    }
}
